package com.yumis.service.modules.car.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CategoryParts;
import com.yumis.service.model.pojo.CategoryService;
import com.yumis.service.modules.car.service.CategoryServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("categoryservice")
public class CategoryServiceController {
    @Autowired
    private CategoryServiceService categoryServiceService;
    /**
     * 新增
     * @param categoryService
     * @return
     */
    @PostMapping("addCategoryService")
    public ResponseEntity<Response> addCategoryService(@Valid CategoryService categoryService){
        categoryServiceService.addCategoryService(categoryService);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("deleteCategoryServiceById")
    public ResponseEntity<Response> deleteCategoryServiceById(@RequestParam("id") Long id){
        categoryServiceService.deleteCategoryServiceById(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据用户id查询
     * @param id
     * @return
     */
    @PostMapping("queryCategoryServiceById")
    public ResponseEntity<Response> queryCategoryServiceById(@RequestParam("id") Long id){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,categoryServiceService.queryCategoryServiceById(id)));
    }

    /**
     * 修改
     * @param categoryService
     * @return
     */
    @PostMapping("updateCategoryService")
    public ResponseEntity<Response> updateCategoryService(@Valid CategoryService categoryService){
        categoryServiceService.updateCategoryService(categoryService);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

}
